package user

import (
	"encoding/json"
	"gitee.com/yanxinfire/geektime-week2-error/pkg/server/user"
	"github.com/gin-gonic/gin"
	"strconv"
)

func GetUser(ctx *gin.Context) {
	userIdstr := ctx.Param("userId")
	userId, err := strconv.Atoi(userIdstr)
	if err != nil {
		ctx.String(400, "User ID is supposed to be a number!")
	}
	resp, err := user.GetUser(userId)
	if err != nil {
		ctx.String(400, err.Error())
	}
	jb, _ := json.Marshal(resp)
	ctx.String(200, string(jb))
}
